/* 
 *  Copyright (C) 2006 James Young
 * `gurumind(a)gmail.com
 * 
 */

using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;

namespace IPDEditor
{

    public class IPDServiceBook : IPDDatabase
    {
        readonly byte fldTypeHRT = 22;
        readonly byte fldTypeTest = 9;

        readonly byte fldTypeRecordType = 0;
        readonly byte fldTypeName = 3;
        readonly byte fldTypeUID = 6;
        readonly byte fldTypeCID = 7;
        readonly byte fldTypeUserID = 5;
        //readonly byte fldTypeDSID = 
        readonly byte fldTypeDescription = 11;

        public IPDServiceBook()
        {
        }

        public IPDServiceBook(IPDName IpdName)
            : base(IpdName)
        { }

        protected override IPDField CreateField(byte type)
        {
            if (type == fldTypeHRT)
            {
                IPDFieldHRT fld = new IPDFieldHRT(this);
                return fld;
            }
            else if (type == fldTypeTest)
            {
                IPDFieldSBAppData tf = new IPDFieldSBAppData(this);
                return tf;
            }
            return base.CreateField(type);
        }

        public int RecordType
        {
            get { return EncUtil.BIN2Int(Items[fldTypeRecordType].data); }
            set { Items[fldTypeRecordType].data = EncUtil.Number2Bin(value); }
        }

        public string Name
        {
            get { return EncUtil.BIN2AsciiOnly(Items[fldTypeName].data); }
            set { Items[fldTypeName].data = EncUtil.AutoString2Bin(value); }
        }

        public string UID
        {
            get { return EncUtil.BIN2AsciiOnly(Items[fldTypeUID].data); }
            set { Items[fldTypeUID].data = EncUtil.AutoString2Bin(value); }
        }

        public string CID
        {
            get { return EncUtil.BIN2AsciiOnly(Items[fldTypeCID].data); }
            set { Items[fldTypeCID].data = EncUtil.AutoString2Bin(value); }
        }

        public int UserID
        {
            get { return EncUtil.BIN2Int(Items[fldTypeUserID].data); }
            set { Items[fldTypeUserID].data = EncUtil.Number2Bin(value); }
        }

        public string Desciption
        {
            get { return EncUtil.BIN2AsciiOnly(Items[fldTypeDescription].data); }
            set { Items[fldTypeDescription].data = EncUtil.AutoString2Bin(value); }
        }

        //public override string ToLongString()
        //{
        //    return string.Format("{2} \r {0} -> \"{1}\"", EncUtil.AutoBin2String(Items[0].data), EncUtil.AutoBin2String(Items[1].data), base.ToString());
        //}

        public override string ToString()
        {
            return EncUtil.AutoBin2String(Items[7].data);
        }
    }
}
